package metrixIMP;

public class metrixBase
{
	protected int rows;
	protected int cols;
	protected double[] eleArr;
	
	public metrixBase()
	{
		this.rows = 1;
		this.cols = 1;
		this.eleArr = new double[1];
		this.eleArr[0] = 0.0;
	}
	
	public metrixBase(int rownum, int colnum, double val)
	{
		if(rownum < 1)
		{
			rownum = 4;
		}
		if(colnum < 1)
		{
			colnum = 4;
		}
		
		this.rows = rownum;
		this.cols = colnum;
		this.eleArr = new double[this.rows*this.cols];
		
		int counter = 0;
		for(int i=0; i<this.rows; ++i)
		{
			for(int j=0; j<this.cols; ++j)
			{
				this.eleArr[counter++] = val;
			}
		}
	}
	
	public metrixBase(int rownum, int colnum, double[] val)
	{
		if(rownum < 1)
		{
			rownum = 4;
		}
		if(colnum < 1)
		{
			colnum = 4;
		}
		
		this.rows = rownum;
		this.cols = colnum;
		this.eleArr = new double[this.rows*this.cols];
		
		int counter = 0;
		
		for(int i=0; i<this.rows; ++i)
		{
			for(int j=0; j<this.cols; ++j)
			{
				if(counter<(val.length))
				{
					this.eleArr[counter] = val[counter];
				}
				else
				{
					this.eleArr[counter] = 0.0;
				}
				++counter;
			}
		}
	}
	
	public void metrixShow()
	{
		System.out.print("\n");
		int counter = 0;
		for(int i=0; i<this.rows; ++i)
		{
			System.out.print("| ");
			for(int j=0; j<this.cols; ++j)
			{
				if(j<(this.cols-1))
				{
					System.out.print(""+this.eleArr[counter++]+"\t\t");
				}
				else
				{
					System.out.print(""+this.eleArr[counter++]);
				}
			}
			System.out.print(" |\n");
		}
	}
}
